<template>
  <view class="zl-flex-col  zl-col-center "
        style="margin-top: 150rpx;"
        v-if="isShow">
    <view class="">
      <!-- <u-avatar :src="uerInfo.avatarUrl?uerInfo.avatarUrl:img"
                size="120"></u-avatar> -->
      <image v-if="uerInfo.avatarUrl"
             style="width: 120rpx;height: 120rpx;border-radius: 50%;overflow: hidden;"
             :src="uerInfo.avatarUrl"></image>
      <image v-else
             style="width: 120rpx;height: 120rpx;border-radius: 50%;overflow: hidden;"
             src="/static/my/avatar.png"></image>
    </view>
    <view class="zl-font-34">
      {{uerInfo.nickName ? uerInfo.nickName :'未设置'}}
    </view>
    <view class="btn  zl-m-t-60  zl-theme-btn"
          @click="login">
      授权登录
    </view>
    <view class="btn2 zl-m-t-30 "
          @click="cancel">
      取消
    </view>
  </view>
</template>

<script>
export default {
  data () {
    return {
      scene: '',
      uerInfo: {},
      isShow: false,
    }
  },
  async onLoad (query) {
    await this.$onLaunched;
    // this.userInfo = uni.getStorageSync('loginInfo')
    // console.log(this.userInfo);
    if (query) {
      console.log(query);
      // this.$util.msg(JSON.stringify(query.scene))
      this.scene = decodeURIComponent(query.scene)
      this.getInfo()
      // this.$util.msg(this.scene)
      this.isShow = true
    }
  },
  methods: {
    getInfo () {
      this.api.account.getmywxsmallloginqrcodestate({
        scene: this.scene,
      }).then(res => {
        if (res.code === 0) {
          this.userInfo = res.data
        } else {
          this.$util.msg(res.msg);
        }
      }).catch(err => {
        this.$util.msg('请检查网络连接！');
      })
    },
    login () {
      this.api.account.confirmwxsmallloginqrcode({
        scene: this.scene,
      }).then(res => {
        if (res.code === 0) {
          this.$util.msg('授权成功');
          setTimeout(() => {
            uni.switchTab({
              url: '/pages/index/index'
            })
          }, 500)
        } else {
          this.$util.msg(res.msg);
        }
      }).catch(err => {
        this.$util.msg('请检查网络连接！');
      })
    },
    cancel () {
      uni.switchTab({
        url: '/pages/index/index'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.btn {
  width: 690rpx;
  height: 88rpx;
  line-height: 88rpx;
  text-align: center;
  font-size: 34rpx;
  border-radius: 10rpx;
}
.btn2 {
  width: 690rpx;
  height: 88rpx;
  line-height: 88rpx;
  text-align: center;
  background-color: #fff;
  border: 2rpx solid #333;
  color: #333;
  font-size: 34rpx;
  border-radius: 10rpx;
}
</style>